package com.leetcode.no110;

// Definition for a binary tree node.
class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    TreeNode(int x) {
        val = x;
    }
}

public class Solution {
    public boolean isBalanced(TreeNode root) {
        if (root == null) {
            return true;
        } else {
            return isBalanced(root.left) &&
                    isBalanced(root.right) &&
                    (Math.abs(depth(root.left) - depth(root.right)) <= 1);
        }
    }

    // 获取一个树的高度
    private int depth(TreeNode root) {
        if(root == null){
            return 0;
        }
        return 1 + Math.max(depth(root.left), depth(root.right));
    }

    public static void main(String[] args) {
        System.out.print("?????");
    }

}